# -*- coding: utf-8 -*-#
#-------------------------------------------------------------------------------
# 建立者:        黄周云  
# Name:         test09
# Description:  监控对象中所有的属性
# Author:       ASUS
# Date:         2019/3/20
#-------------------------------------------------------------------------------


class Rectangle:
    def __init__(self):
        self.width = 0
        self.height  = 0
        self.left = 0
        self.top = 0

    #对属性执行写操作时调用该方法，当设置size和position属性时实际上设置了width、height以及left、top属性
    def __setattr__(self, name, value):
        print("{}被设置，新值为{}".format(name,value))
        if name == "size":
            self.width,self.height = value
        elif name == "position":
            self.left,self.top = value
        else:
            #__dict__是内部维护的特殊成员变量，用于保存成员变量的值
            self.__dict__[name] = value

    def __getattr__(self, name):
        print("{}被获取".format(name))
        if name == "size":
            return self.width,self.height
        elif name == "position":
            return self.left,self.top

    def __delattr__(self, name):
        if name == "size":
            self.width,self.height = 0,0
        elif name == "position":
            self.left,self.top = 0,0

r =Rectangle()
r.size = 300,500
r.position = 100,400
print("size",'=',r.size)
print('position','=',r.position)
del r.size,r.position
print(r.size)
print(r.position)






